package com.webzavod.services;

import com.webzavod.model.User;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created with IntelliJ IDEA.
 * User: slaffka
 * Date: 25.05.12
 * Time: 23:17
 * To change this template use File | Settings | File Templates.
 */
@Service
@Transactional
public class UserService {

    @Autowired
    private SessionFactory sessionFactory;

    @Cacheable(value = "users")
    public User getUserByUsername(String username){
        return (User)sessionFactory.getCurrentSession()
                .createQuery("from User where username = :username")
                .setParameter("username", username)
                .uniqueResult();
    }

}